
package com.atguigu.common.exception;

import com.atguigu.common.result.ResponseEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

@Slf4j
public abstract class Assert {

    /**
     * 断言对象不为空
     * 如果对象obj为空，则抛出异常
     * @param obj 待判断对象
     */
    public static void notNull(Object obj, ResponseEnum responseEnum) {
        if (obj == null) {
            log.info("obj is null...............");
            throw new BusinessException(responseEnum);
        }
    }

    /**
     * 断言对象不为空串
     * 如果对象obj为空，则抛出异常
     * @param obj 待判断对象
     */
    public static void notEmpty(String obj, ResponseEnum responseEnum) {
        if (StringUtils.isEmpty(obj)) {
            log.info("obj is null or ''...............");
            throw new BusinessException(responseEnum);
        }
    }

    /**
     * 断言对象相等
     * 如果对象obj为空，则抛出异常
     * @param va1 待判断对象
     * @param va2 待判断对象
     */
    public static void equals(String va1, String va2,ResponseEnum responseEnum) {
        if (!StringUtils.pathEquals(va1,va2)) {
            log.info("va1 is not equals va2 ''...............");
            throw new BusinessException(responseEnum);
        }
    }

    /**
     * 断言对象相等
     * 如果对象obj为空，则抛出异常
     * @param va1 待判断对象
     * @param va2 待判断对象
     */
    public static void equals(Integer va1, Integer va2,ResponseEnum responseEnum) {
        if (va1 != va2) {
            log.info("va1 is not equals va2 ''...............");
            throw new BusinessException(responseEnum);
        }
    }

    /**
     * 断言对象不为True
     * 如果对象obj为空，则抛出异常
     * @param obj 待判断对象
     */
    public static void isTrue(Boolean obj, ResponseEnum responseEnum) {
        if (obj == null || !obj) {
            log.info("obj is false or null...............");
            throw new BusinessException(responseEnum);
        }
    }
}